package mips.instructions;

public class SLLV extends Instruction {

	private static final String insName = "SLLV";

	private static SLLV instance = null;

	private SLLV() {
	}

	public static final SLLV getInstance() {

		if (instance == null) {

			instance = new SLLV();
		}

		return instance;
	}

	public final void execute(final int instruction) {

		final int rs = (instruction >> 21) & 0x0000001F;
		final int rt = (instruction >> 16) & 0x0000001F;
		final int rd = (instruction >> 11) & 0x0000001F;

		mips.R4300i.GPR[rd] = mips.R4300i.GPR[rt] << (mips.R4300i.GPR[rs] & 0x0000001F);

		mips.R4300i.PC = mips.R4300i.nPC;
		mips.R4300i.nPC = mips.R4300i.PC + 4;
	}

	public final String emit(final int instruction) {

		return 	"		rs = ("+instruction+" >> 21) & 0x0000001F;\n" + 
				"		rt = ("+instruction+" >> 16) & 0x0000001F;\n" + 
				"		rd = ("+instruction+" >> 11) & 0x0000001F;\n" + 
				"		\n" + 
				"		mips.CPU.GPR[rd] = mips.CPU.GPR[rt] << (mips.CPU.GPR[rs] & 0x0000001F);\n" + 
				"		\n" + 
				"		mips.CPU.PC = mips.CPU.nPC;\n" + 
				"		mips.CPU.nPC = mips.CPU.PC + 4;";
	}

	public final String getName() {

		return insName;
	}
}